package com.punch.system.controller;


import com.punch.common.dto.system.ModuleDTO;
import com.punch.common.model.Result;
import com.punch.common.page.PageInfo;
import com.punch.common.query.syste.ModuleQueryInfo;
import com.punch.common.vo.common.OptionVO;
import com.punch.common.vo.system.ModuleVO;
import com.punch.system.service.ModuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 功能模块表 前端控制器
 * </p>
 *
 * @author wjj
 * @since 2020-12-14
 */
@RestController
@Api(value = "ModuleController", tags = "功能模块管理Controller")
public class ModuleController {


    @Resource
    private ModuleService moduleService;

    /**
     * 模块列表
     *
     * @param queryInfo 查询条件
     * @return PageInfo<BannerVO>
     */
    @GetMapping(value = "/modules", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "模块列表", notes = "模块列表", produces = "application/json")
    public Result<PageInfo<ModuleVO>> listModule(@ModelAttribute ModuleQueryInfo queryInfo) {
        return Result.succeed(moduleService.listModule(queryInfo));
    }


    /**
     * 保存功能模块
     *
     * @param moduleDTO 提交表单
     * @return id
     */
    @PostMapping(value = "/module", produces = "application/json; charset=utf-8")
    @ApiOperation(value = " 保存功能模块", notes = " 保存功能模块", produces = "application/json")
    public Result<Integer> saveModule(@RequestBody ModuleDTO moduleDTO) {
        return Result.succeed(moduleService.saveModule(moduleDTO));
    }

    /**
     * 修改功能模块
     *
     * @param moduleDTO 提交表单
     * @return id
     */
    @PutMapping(value = "/module", produces = "application/json; charset=utf-8")
    @ApiOperation(value = " 修改功能模块", notes = " 修改功能模块", produces = "application/json")
    public Result<Integer> updateModule(@RequestBody ModuleDTO moduleDTO) {
        return Result.succeed(moduleService.updateModule(moduleDTO));
    }


    /**
     * 功能模块详情
     *
     * @param moduleId 模块id
     * @return ModuleVO
     */
    @GetMapping(value = "/module/{moduleId}", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "功能模块详情", notes = "功能模块详情", produces = "application/json")
    public Result<ModuleVO> getModule(@PathVariable Integer moduleId) {
        return Result.succeed(moduleService.getModule(moduleId));
    }

    /**
     * 删除功能模块
     *
     * @param moduleId 模块id
     * @return id
     */
    @DeleteMapping(value = "/module/{moduleId}", produces = "application/json; charset=utf-8")
    @ApiOperation(value = " 删除功能模块", notes = " 删除功能模块", produces = "application/json")
    public Result<Integer> deleteModule(@PathVariable Integer moduleId) {
        return Result.succeed(moduleService.deleteModule(moduleId));
    }


    /**
     * 修改模块状态
     *
     * @param moduleId 模块id
     * @param status   状态 0-不显示 1-显示
     * @return moduleId
     */
    @PutMapping(value = "/module/{moduleId}/status/{status}", produces = "application/json; charset=utf-8")
    @ApiOperation(value = " 修改模块状态", notes = " 修改模块状态", produces = "application/json")
    public Result<Integer> updateModuleStatus(@PathVariable Integer moduleId, @PathVariable Integer status) {
        return Result.succeed(moduleService.updateModuleStatus(moduleId, status));
    }

    /**
     * 简单模块列表
     *
     * @return List<OptionVO>
     */
    @GetMapping(value = "/modules/simple", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "简单模块列表", notes = "简单模块列表", produces = "application/json")
    public Result<List<OptionVO<Integer>>> listSimpleModule(@RequestParam("type") Integer type) {
        return Result.succeed(moduleService.listSimpleModule(type));
    }
}
